package Test02;

import java.util.Scanner;

public class StudentUI {
    Scanner sc = new Scanner(System.in);
    SupperArray supAry = new SupperArray();

    /**
     * ui
     */
    public void ui(){
        System.out.println("欢迎进入学生管理系统，请选择\n " +
                "1--增加学生 2--删除学生 3--查询 4--修改信息 5--退出");
        menu();
    }

    /**
     * 菜单
     */
    public void menu(){
        int input = sc.nextInt();
        if(input == 1){
            add();
        }else if(input == 2){
            delete();
        }else if(input == 3){
            search();
        }else if(input == 4){
            modify();
        }else if(input == 5){
            System.out.println("再见");
            System.exit(0);
        }else {
            System.out.println("输入有误");
        }
    }



    /**
     * 添加学生
     */
    public void add(){
        System.out.println("请输入要添加的学生姓名：");
        String name = sc.next();
        System.out.println("请输入该学生年龄：");
        int age = sc.nextInt();
        System.out.println("请输入该学生性别：");
        String gender = sc.next();
        supAry.add(new Student(name,age,gender));
        System.out.println("添加成功");
        ui();
    }
    /**
     *  删除学生
     */
    public void delete(){
        System.out.println("请输入要删除的学生姓名：");
        String name = sc.next();
        for (int i = 0;i < supAry.size();i++){
            Student student  = (Student)supAry.get(i);
            if(name.equals(student.getName())){
                supAry.remove(i);
            }else {
                System.out.println("输入有误或该没有该学生");
            }
            menu();
        }
    }

    /**
     * 查询学生
     */
    public void search(){
        System.out.println("请输入您要查找的学生姓名：");
        String name = sc.next();
        for (int i = 0;i < supAry.size();i++){
            Student student  = (Student)supAry.get(i);
            if(name.equals(student.getName())){
                System.out.println(
                                "姓名 ：\n" + student.getName() + "\n" + "年龄 ：\n" + student.getAge() + "\n" + "性别 ：\n"
                        + student.getGender());
            }else {
                System.out.println("输入有误或没有该学生");
            }
        }
        menu();
    }

    /**
     * 修改学生信息
     */
    public void modify(){
        System.out.println("请输入您要修改的学生姓名");
        String name = sc.next();
        for (int i = 0;i < supAry.size();i++){
            Student student = (Student)supAry.get(i);
            if (name.equals(student.getName())){
                System.out.println("请输入要修改的姓名");
                String name1 = sc.next();
                System.out.println("请输入要修改的年龄");
                int age1 = sc.nextInt();
                System.out.println("请输入要修改的性别");
                String gender1 = sc.next();
                student.setName(name1);
                student.setAge(age1);
                student.setGender(gender1);
            }else {
                System.out.println("输入有误或没有该学生");
            }
        }
        menu();
    }

}
